package com.emr.web.controller.emr;


import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.emr.common.annotation.Log;
import com.emr.common.enums.BusinessType;
import com.emr.module.domain.Jieyue;
import com.emr.module.service.IJieyueService;
import com.emr.module.service.IPersonalService;
import com.emr.system.domain.SysUser;
import com.emr.system.service.ISysUserService;
import com.emr.web.core.base.BaseController;
import com.emr.framework.web.page.TableDataInfo;
import com.emr.common.base.AjaxResult;

/**
 * 病历借阅 信息操作处理
 * 
 * @author emr
 * @date 2019-02-26
 */
@Controller
@RequestMapping("/module/jieyue")
public class JieyueController extends BaseController
{
    private String prefix = "module/jieyue";
	
	@Autowired
	private IJieyueService jieyueService;
	@Autowired
	private ISysUserService isysUserService;
	
	@RequiresPermissions("module:jieyue:view")
	@GetMapping()
	public String jieyue()
	{
	    return prefix + "/jieyue";
	}
	
	/**
	 * 查询病历借阅列表
	 */
	@RequiresPermissions("module:jieyue:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Jieyue jieyue,HttpSession session)
	{
		SysUser user = getUser();
		startPage();
        List<Jieyue> list = jieyueService.selectJieyueList(jieyue);
		return getDataTable(list);
	}
	
	/**
	 * 新增病历借阅
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存病历借阅
	 */
	@RequiresPermissions("module:jieyue:add")
	@Log(title = "病历借阅", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Jieyue jieyue)
	{		
		return toAjax(jieyueService.insertJieyue(jieyue));
	}

	/**
	 * 修改病历借阅
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Jieyue jieyue = jieyueService.selectJieyueById(id);
		if(jieyue.getJieyuerenId() == null || "".equals(jieyue.getJieyuerenId())){
			mmap.put("posts", isysUserService.selectsuoyouAll());
		}else{
			mmap.put("posts", isysUserService.selectsuoyouAlls(jieyue.getJieyuerenId()));
		}
		mmap.put("jieyue", jieyue);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存病历借阅
	 */
	@RequiresPermissions("module:jieyue:edit")
	@Log(title = "病历借阅", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Jieyue jieyue)
	{	

		return toAjax(jieyueService.updateJieyue(jieyue));
	}
	
	/**
	 * 删除病历借阅
	 */
	@RequiresPermissions("module:jieyue:remove")
	@Log(title = "病历借阅", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(jieyueService.deleteJieyueByIds(ids));
	}
	
}
